﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using OpenExpressApp.Editors;
using System.Windows.Data;
using Csla.Wpf;
using System.Windows;

namespace OpenExpressApp.Module.WPF.Editors
{
    public class BooleanPropertyEditor : WPFPropertyEditor
    {
        private CheckBox _cb;

        public BooleanPropertyEditor(BusinessObjectPropertyInfo propertyInfo, IObjectView view)
            : base(propertyInfo, view) { }

        protected override FrameworkElement CreateEditingElement()
        {
            this._cb = new CheckBox() { Name = PropertyInfo.Name };
            Binding valueBinding = new Binding(PropertyInfo.Name);
            if (this.PropertyInfo.RuntimeProperty.CanWrite == false)
            {
                valueBinding.Mode = BindingMode.OneWay;
            }
            this._cb.SetBinding(CheckBox.IsCheckedProperty, valueBinding);
            this._cb.HorizontalAlignment = HorizontalAlignment.Center;
            this._cb.VerticalAlignment = VerticalAlignment.Center;
            return _cb;
        }
    }
}
